package com.wc.alorithm_luogu.P1093;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/5/7 20:58
 * @description https://www.luogu.com.cn/problem/P1093
 * 奖学金
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Student[] students = new Student[n];

        for (int i = 0; i < n; i++) {
            Student student = new Student();
            student.id = i + 1;
            student.Chinese = sc.nextInt();
            student.math = sc.nextInt();
            student.English = sc.nextInt();
            student.setSum();
            students[i] = student;
        }

        // 手写一个排序
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student s1, Student s2) {
                if (s1.sum != s2.sum) {
                    return s2.sum - s1.sum;
                } else if (s1.Chinese != s2.Chinese) {
                    return s2.Chinese - s1.Chinese;
                } else {
                    return s1.id - s2.id;
                }
            }
        });

        for (int i = 0; i < 5; i++) {
            System.out.println(students[i]);
        }
    }

    static class Student {
        int id;
        int Chinese;
        int math;
        int English;
        int sum;

        public void setSum() {
            sum = Chinese + math + English;
        }

        @Override
        public String toString() {
            return id + " " + sum;
        }
    }
}

